<template>
	<view class="uni-column">
			<view class="uni-form-item uni-column">
				<input class="uni-input" confirm-type="search" v-model="A_name" placeholder="请输入活动标题" />
			</view>
		<view >
	
			<view >
				<view class="example-body" >
					<uni-file-picker limit="9" title="选择图片"></uni-file-picker>
				</view>
			</view>

				
			<view >
				<view class="uni-list" >
					<view class="uni-list-cell">
						<view class="uni-list-cell-left">
							活动类型
						</view>
					<view class="uni-list-cell-db">
						<picker @change="bindPickerChange" :value="index" :range="array"  >
							<view class="uni-input">{{array[index]}}</view>
						</picker>
					</view>
					</view>
				</view>
				<view class="uni-form-item uni-column" >
						<input class="uni-input" v-model="A_place" placeholder="请输入地点" />
				</view>
				<view class="uni-form-item uni-column" >
						<input class="uni-input" v-model="A_score" placeholder="请输入积分" />
				</view>
				<view class="uni-form-item uni-column" >
						<input class="uni-input" v-model="A_reward" placeholder="请输入劳酬" />
				</view>
				<view class="uni-form-item uni-column" >
						<input class="uni-input" v-model="A_max_number" placeholder="活动最大人数" />
				</view>
			</view>
		</view>		
		<view>
			<view class="uni-list">
				<view class="uni-list-cell">
					<view class="uni-list-cell-left">
						抢单截止
					</view>
					<view class="example-body">
						<uni-datetime-picker returnType="string" v-model="A_T_deadline" @change="changeLog($event)" />
					</view>
				</view>
				
				<view class="uni-list-cell">
					<view class="uni-list-cell-left">
						报名截至
					</view>
					<view class="example-body">
						<uni-datetime-picker returnType="string" v-model="A_S_deadline" @change="changeLog($event)" />
					</view>
				</view>
			
				<view class="uni-list">
					<view class="uni-list-cell">
						<view class="uni-list-cell-left">
							活动开始
						</view>

						<view class="example-body">
							<uni-datetime-picker returnType="string" v-model="A_start_time" @change="changeLog($event)" />
						</view>
					</view>
				</view>

			<view class="uni-list">
				
				<view class="uni-list-cell">
					<view class="uni-list-cell-left">
						活动结束
					</view>

					<view class="example-body">
						<uni-datetime-picker returnType="string" v-model="A_end_time" @change="changeLog($event)" />
					</view>
				</view>
			</view>
			</view>
		</view>
		<view>
				<view class="uni-textarea">
					<textarea placeholder-style="color:#F76260" class="shadow" v-model="A_describe" placeholder="请输入活动描述"/>
				</view>
				<button type="primary" plain="true" style="margin-top: 10px;" @click="publish()">发布</button>
	   </view>
	</view>
	
</template>

<script>
export default {
    data() {
        const currentDate = this.getDate({
            format: true
        })
        return {
            title: 'picker',
            array: ['文体活动', '艺术活动', '心理活动', '体育活动','IT技能','摄影技能','英语活动','郊游活动'],
            index: 0,
            date1: currentDate,
			date2: currentDate,
			date3: currentDate,
            time: '12:01',
			httpurl: getApp().globalData.weburl, //app.vue中定义的全局变量，后端ip地址,
			A_id:0,
			A_name:'',
			A_describe:'',
			A_score:'',
			A_publish_time:'',
			A_T_deadline:'',
			A_S_deadline:'',
			A_start_time:'',
			A_end_time:'',
			A_place:'',
			A_reward:'',
			A_max_number:'',
			A_is_robbed:'',
			Type_id:'',
			A_cover:'',
			A_type:'',
			W_id:0,
        }
    },
    computed: {
        startDate() {
            return this.getDate('start');
        },
        endDate() {
            return this.getDate('end');
        }
    },
    methods: {
        bindPickerChange: function(e) {
            console.log('picker发送选择改变，携带值为', e.detail.value)
			this.index = e.detail.value;
            this.Type_id=e.detail.value+1
        },
        bindDateChange1: function(e) {
            this.date1 = e.detail.value
        },
		bindDateChange2: function(e) {
		    this.date2 = e.detail.value
		},
		bindDateChange3: function(e) {
		    this.date3 = e.detail.value
		},
        bindTimeChange: function(e) {
            this.time = e.detail.value
        },
        getDate(type) {
            const date = new Date();
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            let day = date.getDate();

            if (type === 'start') {
                year = year - 60;
            } else if (type === 'end') {
                year = year + 2;
            }
            month = month > 9 ? month : '0' + month;
            day = day > 9 ? day : '0' + day;
            return `${year}-${month}-${day}`;
        },
		publish(){
		 var that=this;
		 uni.request({
		     url: that.httpurl+'publishActivity/', //服务器地址+接口名
		     data: {
		   W_id:getApp().globalData.userid,
		   A_id:that.A_id,
		   A_name:that.A_name,
		   A_describe:that.A_describe,
		   A_score:that.A_score,
		   A_publish_time:that.A_publish_time,
		   A_T_deadline:that.A_T_deadline,
		   A_S_deadline:that.A_S_deadline,
		   A_start_time:that.A_start_time,
		   A_end_time:that.A_end_time,
		   A_place:that.A_place,
		   A_reward:that.A_reward,
		   A_max_number:that.A_max_number,
		   A_is_robbed:that.A_is_robbed,
		   Type_id:that.Type_id,
		   A_cover:that.A_cover,
		   A_type:that.A_type,
		     },
		  method: 'POST',
		     header: { 
		   'X-Requested-With': 'XMLHttpRequest',
		   "Accept": "application/json",
		   "Content-Type": "application/json; charset=UTF-8"
		  },
		  dataType: 'json',
		     success: (res) => {
		     console.log("request success");
		        console.log("跳转");
				uni.navigateBack({
					delta:1
				});
		     },
		  fail: (res) => {
		   console.log("request fail");
		     },
		 });
		},
    }
}
</script>

<style>
.uni-picker-tips {
	font-size: 12px;
	color: #666;
	margin-bottom: 15px;
	padding: 0 15px;
	/* text-align: right; */
}
.shadow {

	 width: 100%;
	 height: 80px;
     -moz-box-shadow: inset 0 0 10px #CCC;
     -webkit-box-shadow: inset 0 0 10px #CCC;
     box-shadow: inset 0 0 10px #CCC;
	 
}
	.example-body {
		padding: 10px;
		padding-top: 0;
	}
</style>
